import { defineStore } from "pinia";
import { ref } from "vue";
import {getAllEmployeeAPI} from "@/network/employee/employee";
import {ElMessage} from "element-plus";
import {getAllClassesAPI} from "@/network/class/class";


export const useClassManagerStore = defineStore("classManager", () => {
    const allClassList = ref([])
    function getAllClass() {
        const data = {
            "status_list": [
                1,2
            ]
        }
        getAllClassesAPI(data).then(res=>{
            if(!res){
                return ElMessage.error("未收到返回")
            }

            if(res.status !== 200){
                return ElMessage.error(res.message?res.message:res.status)
            }

            if(!res.data){
                return ElMessage.error("返回的数据为空")
            }

            if(res.data.code !== 0) {
                return ElMessage.error(res.data.message)
            }

            if(res.data.code===0 && res.data.data){
                allClassList.value = res.data.data
            }
        }).catch(error=>{
            ElMessage.error(error.message)
        })
    }
    //    设置考勤管理的弹框状态控制
    const attendanceManagerDialogVisible = ref(false);
    function toggleAttendanceManagerDialogVisible() {
        attendanceManagerDialogVisible.value = !attendanceManagerDialogVisible.value;
    }

//    考勤信息查看的弹框状态控制
    const attendanceViewDialogVisible = ref(false);
    function toggleAttendanceViewDialogVisible() {
        attendanceViewDialogVisible.value = !attendanceViewDialogVisible.value;
    }


//    成绩管理的弹框状态控制
    const scoreManagerDialogVisible = ref(false);
    function toggleScoreManagerDialogVisible() {
      scoreManagerDialogVisible.value = !scoreManagerDialogVisible.value;
    }

    return {
        allClassList,
        getAllClass,
        attendanceManagerDialogVisible,
        toggleAttendanceManagerDialogVisible,
        attendanceViewDialogVisible,
        toggleAttendanceViewDialogVisible,
        scoreManagerDialogVisible,
        toggleScoreManagerDialogVisible,
    }
})
